package com.thz.friend.controller.exam;

import com.thz.common.core.controller.BaseController;
import com.thz.common.core.pojo.TableDataInfo;
import com.thz.common.core.result.Result;
import com.thz.friend.pojo.exam.dto.ExamQueryDTO;
import com.thz.friend.pojo.exam.dto.ExamRankDTO;
import com.thz.friend.service.exam.IExamService;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description
 * @Author thz
 * @Date 2025/3/27
 */
@RestController
@RequestMapping("/exam")
public class ExamController extends BaseController {

    @Autowired
    private IExamService examService;

    @GetMapping("/semiLogin/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO) {
        return getTableDataInfo(examService.list(examQueryDTO));
    }

    @GetMapping("/semiLogin/listHomework")
    public TableDataInfo listHomework(@NonNull @RequestParam("courseId") Long courseId) {
        return getTableDataInfo(examService.listHomework(courseId));
    }

    @GetMapping("/rank/list")
    public TableDataInfo rankList(ExamRankDTO examRankDTO) {
        return examService.rankList(examRankDTO);
    }

    /*
     * @description: 从redis缓存中获取竞赛列表
     * @author: thz
     * @date: 2025/3/30 17:29
     * @param: [examQueryDTO]
     * @return: com.thz.common.core.pojo.TableDataInfo
     **/
    @GetMapping("/semiLogin/redis/list")
    public TableDataInfo redisList(ExamQueryDTO examQueryDTO) {
        return examService.redisList(examQueryDTO);
    }

    /*
     * @description: 获取竞赛中的第一个题目
     * @author: thz
     * @date: 2025/3/30 17:29
     * @param: [examId]
     * @return: com.thz.common.core.result.Result<java.lang.String>
     **/
    @GetMapping("/getFirstQuestion")
    public Result<String> getFirstQuestion(Long examId) {
        return Result.ok(examService.getFirstQuestion(examId));
    }

    @GetMapping("/preQuestion")
    public Result<String> preQuestion(Long examId, Long questionId) {
        return Result.ok(examService.preQuestion(examId, questionId));
    }

    @GetMapping("/nextQuestion")
    public Result<String> nextQuestion(Long examId, Long questionId) {
        return Result.ok(examService.nextQuestion(examId, questionId));
    }

}
